namespace PMS.BLL
{
    using PMS.Common;
    using PMS.DBUtility;
    using System;
    using System.Text;

    public class BackupBLL
    {
        public bool Add(int type, string fileName)
        {
            try
            {
                StringBuilder builder = new StringBuilder();
                if (type == 0)
                {
                    builder.Append(" Backup Database PMS");
                }
                else if (type == 1)
                {
                    builder.Append(" Backup Log PMS");
                }
                builder.Append(" To disk='" + fileName + "'");
                DBHelper.ExecuteSql(builder.ToString());
                return true;
            }
            catch (Exception exception)
            {
                Log.Write(exception.Message);
                return false;
            }
        }

        public bool Recovery(string backupFile)
        {
            try
            {
                StringBuilder builder = new StringBuilder();
                if (backupFile.IndexOf("db_") > 0)
                {
                    builder.Append(" RESTORE DATABASE PMS");
                }
                else
                {
                    builder.Append(" RESTORE Log PMS");
                }
                builder.Append(" FROM disk='" + backupFile + "'");
                DBHelper.ExecuteSql(builder.ToString());
                return true;
            }
            catch (Exception exception)
            {
                Log.Write(exception.Message);
                return false;
            }
        }
    }
}

